package com.lzb.musicplayer.adapter;

import android.graphics.Bitmap;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.basic.ProviderMultiAdapter;
import com.lzb.musicplayer.R;
import com.lzb.musicplayer.bean.GroupMusicInfo;
import com.lzb.musicplayer.bean.MusicFile;
import com.lzb.musicplayer.bean.PlayListBean;
import com.lzb.musicplayer.utils.MusicScannerUtil;

public class PlayListAdapter extends ProviderMultiAdapter<PlayListBean> {

    public PlayListAdapter() {
        addItemProvider(new PlayListProvider());
    }

    private class PlayListProvider extends BaseItemProvider<PlayListBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_play_list;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, PlayListBean bean) {
            if (bean.getMusicFileList() != null && bean.getMusicFileList().size() > 0) {
                MusicFile musicFile = bean.getMusicFileList().get(0);
                Bitmap albumCover = MusicScannerUtil.getAlbumArt(getContext(), musicFile.getAlbumCover());
                Bitmap bit = MusicScannerUtil.getAlbumArt(getContext(), musicFile.getArtistCover());
                baseViewHolder.setImageResource(R.id.ivPlayListItemImg, R.drawable.bofangliebiao);
                if (albumCover != null) {
                    baseViewHolder.setImageBitmap(R.id.ivPlayListItemImg, albumCover);
                } else {
                    if (bit != null) {
                        baseViewHolder.setImageBitmap(R.id.ivPlayListItemImg, bit);
                    }
                }
            } else {
                baseViewHolder.setImageResource(R.id.ivPlayListItemImg, R.drawable.bofangliebiao);
            }
            baseViewHolder.setText(R.id.tvPlayListItemName, bean.getName());
            baseViewHolder.setText(R.id.tvPlayListItemSize, bean.getMusicFileList().size() + getContext().getString(R.string.music));
        }
    }
}